﻿using System;
using System.Windows.Forms;

namespace wecker {
    public partial class Gui : Form {
        public Gui() {
            InitializeComponent();
        }

        public event Action Geladen;
        public event Action<DateTime> Weckzeit_einstellen;

        delegate void SetTextToLabelThreadSafeCallback(Label lab,string text);
        private void SetTextToLabelThreadSafe(Label lab, string text) {
            if (lab.InvokeRequired) {
                var d = new SetTextToLabelThreadSafeCallback(SetTextToLabelThreadSafe);
                Invoke(d, new object[] { text });
            }
            else {
                lab.Text = text;
            }
        }

        public void setze_aktuelle_Uhrzeit(DateTime p_aktuelleUhrzeit) {
            SetTextToLabelThreadSafe(labUhrzeit, p_aktuelleUhrzeit.ToLongTimeString());
        }

        public void setze_Restzeit(TimeSpan p_Restzeit) {
            SetTextToLabelThreadSafe(labRestzeit, p_Restzeit.TotalSeconds.ToString() );
        }

        private void FrmWecker_Load(object sender, EventArgs e) {
            Geladen();
        }

        private void buWeckzeitEinstellen_Click(object sender, EventArgs e) {
            Weckzeit_einstellen(dtpWeckzeit.Value );
        }
    }
}
